#include <REGX52.H>
#include "I2C.H"
#include "LCD1602.H"

#define AT24C02_ADDRESS 0XA0 //宏定义写入的地址

void AT24C02_WriteByte(unsigned char WordAddress,Date) //字节的写入

{
//	unsigned char Ack;
	I2C_Start();//调用发送开始函数
	I2C_SendByte(AT24C02_ADDRESS);	//调用发送字节函数
	I2C_ReceiveAck();//调用接受应答函数
	//LCD_ShowChar(2,1,"Ack");//尝试（失败）
	I2C_SendByte(WordAddress);
	I2C_ReceiveAck();
	I2C_SendByte(Date);
	I2C_ReceiveAck();
	I2C_Stop();

	
}
unsigned AT24C02_ReadByte(unsigned char WordAddress)//字节的读取
{		
	unsigned char Date;
	I2C_Start();
	I2C_SendByte(AT24C02_ADDRESS);
	I2C_ReceiveAck();
	I2C_SendByte(WordAddress);
	I2C_ReceiveAck();
	I2C_Start();
	I2C_SendByte(AT24C02_ADDRESS|0X01);
	I2C_ReceiveAck();
	Date=I2C_ReceiveByte();
	I2C_SendAck(1);
	I2C_Stop();
	
	
	
	
	return Date;
	
	
}
